package com.shj.em.biz.sys.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.shj.em.biz.sys.entity.DeptEmp;
import com.shj.em.biz.sys.mapper.DeptEmpMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;

/**
 * 部门员工管理 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-07-05
 */
@Service
public class DeptEmpServiceImpl extends ServiceImpl<DeptEmpMapper, DeptEmp> implements DeptEmpService {

    @Autowired
    DeptEmpMapper deptempMapper;

    public Page<DeptEmp> queryDeptEmpPage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<DeptEmp> page = new Page(pageNo, pageSize);
        List<DeptEmp> list = deptempMapper.queryDeptEmpPage(page, params);
        return page.setRecords(list);
    }

    public DeptEmp findEnterDeptDate(Long deptId, Long empId){
        Wrapper<DeptEmp> wrapper = new EntityWrapper<>();
        wrapper.eq("del_flag", 0).eq("dept_id", deptId)
                .eq("emp_id", empId);
        List<DeptEmp> list = deptempMapper.selectList(wrapper);
        if(list == null || list.isEmpty()){
            return null;
        }else{
            return list.get(0);
        }
    }

}
